import { ResPage } from "@/api/interface/index";
import { Role } from "@/api/interface/roleManagement";
import { BASE } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 角色管理模块
 */
// 获取角色户列表
export const getRoleList = (params?: object) => {
  return http.get<ResPage<Role.ResRoleList>>(BASE + `/role/`, params); // 正常 post json 请求  ==>  application/json
};
// 删除角色
export const roleTerminate = (params: { ids: any[] }) => {
  return http.delete(BASE + `/role/${params.ids[0]}/`); // 正常 post json 请求  ==>  application/json
};

// 关联用户
export const roleAssociatedUser = (id: number, params: object) => {
  return http.post(BASE + `/role/${id}/user/`, params);
};

// 获取角色权限详情
export const getRoleDetail = (id: number) => {
  return http.get<Role.ResRoleDetail>(BASE + `/role/${id}/`);
};

// 获取权限树列表
export const getPermissionList = () => {
  return http.get<Role.ResPermissionList>(BASE + `/permission/base/`);
};

// 创建角色
export const createRole = params => {
  return http.post(BASE + `/role/`, params);
};

// 编辑角色
export const roleModify = (id, params) => {
  return http.put(BASE + `/role/${id}/`, params);
};

// 获取可关联的用户
export const getUserList = () => {
  return http.get<any[]>(BASE + `/role/user_list/`);
};
